#ifndef CONTROLLER_H
#define CONTROLLER_H

#include <QObject>
#include <QDebug>
#include <QTime>
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusInterface>
#include <QtDBus/QDBusConnectionInterface>
#include <MBanner>
#include <MNotification>
#include <policy/resource-set.h>
#include <qmkeys.h>
#include "gconfitemqmlproxy.h"
#include <QDir>
#include <QFile>

class MediaKeys : public QObject
{
    Q_OBJECT
public:
    explicit MediaKeys(QObject *parent = 0);

    GConfItemQmlProxy* gconfUpAction;
    GConfItemQmlProxy* gconfDownAction;
    GConfItemQmlProxy* gconfStatus;
    GConfItemQmlProxy* gconfLongPress;
    GConfItemQmlProxy* gconfPressDuration;

    void setGconfUpAction(GConfItemQmlProxy*);
    void setGconfDownAction(GConfItemQmlProxy*);
    void setGconfStatus(GConfItemQmlProxy*);
    void setGconfLongPress(GConfItemQmlProxy*);
    void setGconfPressDuration(GConfItemQmlProxy*);

private:
    //! A QmKeys instance to get signals about volume-key presses
    MeeGo::QmKeys *hwkeys;
    //! A resource object for volume(zoom)-hardware keys
    ResourcePolicy::ResourceSet *volResourceSet;

    enum Action {
        PlayPause,
        Previous,
        Next
    };
    Action volUpAction;
    Action volDownAction;
    bool volumeUpPressed;
    bool volumeDownPressed;
    bool onNextKeyReleased;
    bool useLongPress;
    int volumeStep;
    int longPressDuration;
    QTime volUpTime;
    QTime volDownTime;


    bool isMusicSuiteServiceRegistered();
    bool playbackState();
    void previous();
    void next();
    void togglePlayback();

    int getVolume();
    bool increaseVolume();
    bool decreaseVolume();



private slots:
    void keyEvent (MeeGo::QmKeys::Key key, MeeGo::QmKeys::State state);
    void keyResourceAcquired();
    void keyResourceReleased();
    void keyResourceDenied();

    void updateStatus();
    void updateUpAction();
    void updateDownAction();
    void updateLongPress();
    void updatePressDuration();
};

#endif // CONTROLLER_H
